package com.api.mapper;

import com.api.pojo.Task;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TaskMapper {

    @Insert("insert into task(uid, name, st, et) value(#{uid}, #{name}, #{st}, #{et})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void create(Task task);

    @Delete("delete from task where id = #{id}")
    void remove(Integer id);

    @Update("update task set uid = #{uid}, name = #{name}, st = #{st}, et = #{et} where id = #{id}")
    void update(Task task);

    @Select("select * from task limit #{pageNo}, #{pageSize}")
    List<Task> get(Integer pageNo, Integer pageSize);

    @Select("select count(*) from task")
    Integer count();

    @Select("select * from task where name like #{name} limit #{pageNo}, #{pageSize}")
    List<Task> getByName(String name, Integer pageNo, Integer pageSize);

    @Select("select count(*) from task where name like #{name}")
    Integer countByName(String name);

    @Select("select id from user where role = 2")
    List<Integer> getUserIds();

    @Select("select * from task where id = #{id}")
    Task getById(Integer id);
}
